﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;

namespace CFConsole
{
    public class MCPEntities : DbContext
    {
        public DbSet<User> Users { get; set; }
        public DbSet<Check> Checks { get; set; }
        public DbSet<Item> Items { get; set; }
        //public DbSet<ItemCategory> ItemCategories { get; set; }
        public DbSet<Category> Categories { get; set; }
    }

    public class User
    {
        [Key]
        public Guid ID { get; set; }

        [Required]
        public string Username { get; set; }
        [Required]
        public string Password { get; set; }

        public Settings Settings { get; set; }
    }

    [ComplexType]
    public class Settings
    {
        public double? MonthIncome { get; set; }
        public double? MinBalance { get; set; }
        public string Email { get; set; }
    }

    public class Check
    {
        [Key]
        public Guid ID { get; set; }

        public Guid UserID { get; set; }
        [ForeignKey("UserID")]
        public virtual User User { get; set; }

        public DateTime Date { get; set; }
        
        [Required]
        public double TotalPrice { get; set; }
    }

    public class Item
    {
        [Key]
        public Guid ID { get; set; }
        
        [MaxLength(100)]
        public string Name { get; set; }

        public double? UnitPrice { get; set; }
        public double? Amount { get; set; }
        public double? Price { get; set; }

        public Guid CheckID { get; set; }
        [ForeignKey("CheckID")]
        public virtual Check Check { get; set; }

        public List<Category> Categories { get; set; }
    }

    //public class ItemCategory
    //{
    //    public Guid ItemID { get; set; }
    //    [ForeignKey("ItemID")]
    //    public virtual Item Item { get; set; }

    //    public Guid CategoryID { get; set; }
    //    [ForeignKey("CategoryID")]
    //    public virtual Category Category { get; set; }
    //}

    public class Category
    {
        [Key]
        public Guid ID { get; set; }
        
        [Required]
        [MaxLength(100)]
        public string CategoryName { get; set; }

        public virtual List<Item> Items { get; set; }
    }
}